package com.ojoin.trade.common_core.web.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ojoin.trade.common.exception.BusinessException;
import com.ojoin.trade.common.utils.LogUtils;
import com.ojoin.trade.common.web.dao.BaseDao;
import com.ojoin.trade.common.web.service.impl.BaseServiceImpl;
import com.ojoin.trade.common_core.web.dao.TbFactoringCompanyDao;
import com.ojoin.trade.common_core.web.domain.TbFactoringCompany;
import com.ojoin.trade.common_core.web.domain.TbFactoringOperator;
import com.ojoin.trade.common_core.web.service.FactoringCompanyBaseService;
import com.ojoin.trade.common_core.web.service.FactoringOperatorBaseService;
import com.ojoin.trade.common_core.web.service.MerchantUserBaseService;

/**
 * 保理公司服务实现
 * @author guoting
 *
 */
@Service
public class FactoringCompanyBaseServiceImpl extends BaseServiceImpl<TbFactoringCompany> implements
		FactoringCompanyBaseService {

	@Autowired
	private TbFactoringCompanyDao dao;
	
	@Autowired
	private FactoringOperatorBaseService operatorService;
	
	@Autowired
	private MerchantUserBaseService userService;
	
	@Override
	public TbFactoringCompany queryFactoringCompanyVOByOperatorID(
			int operatorid) throws BusinessException {
		LogUtils.getT0loanLog().info("查询操作员id->" + operatorid + "对应操作员信息.");
		TbFactoringOperator operatorvo = operatorService.queryById(operatorid);
		if (operatorvo == null)
			return null;
		
		int companyid = operatorvo.getIdOfTbFactoringCompany();
		LogUtils.getT0loanLog().info("查询保理公司id->" + operatorid + "对应保理公司信息.");
		TbFactoringCompany companyvo = this.getBaseDao().selectById(companyid);
		
		return companyvo;
	}

	@Override
	public String queryFactoringCompanyMhtNoByOperatorID(
			int operatorid) throws BusinessException {
		TbFactoringCompany companyvo = this.queryFactoringCompanyVOByOperatorID(operatorid);
		Integer joinuserid = companyvo.getIdOfTbMerchantUser();
		
		if (joinuserid == null)
			throw new BusinessException("保理员对应的九盈用户为空，请检查.");
		
		LogUtils.getT0loanLog().info("查询保理员id->" + operatorid + "对应保理公司的支付商户号.");
		return userService.queryPayUserByJoinUserID(joinuserid);
	}

    @Override
    public Integer getCompanyByjoind(int joinid) throws BusinessException {
        return dao.getCompanyByjoind(joinid);
    }

    @Override
	protected BaseDao<TbFactoringCompany> getBaseDao() {
		return dao;
	}


}
